/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * Licensed under Simplified BSD License
 *
 *
 * @author: jin Chen 
 * @date: Nov 17, 2004$
 * @version: 1.0
 */
package edu.psu.geovista.app.pcp.toolkits.selectcontrol.action;

import edu.psu.geovista.app.pcp.toolkits.selectcontrol.SelectItemsPane;
import epoviz.trex.common.swing.frame.action.SimpleActionManager;
import epoviz.trex.common.swing.utils.ImageUtils;

import javax.swing.*;

public class ActionManager extends SimpleActionManager {
    public static final String ACTION_UP="MoveUp";
    public static final String ACTION_DOWN="MoveDown";
    public static final String ACTION_TOP="MoveTop";
    public static final String ACTION_BOTTOM="MoveBottom";
    public static final String ACTION_RIGHT="MoveRight";
    public static final String ACTION_LEFT="MoveLeft";
    public static final String ACTION_RIGHTALL="MoveAllRight";
    public static final String ACTION_LEFTALL="MoveAllLeft";
    public static final String ACTION_APPLY="Apply";

    SelectItemsPane app;// the application that own the ActionManager

    public ActionManager() {
        //createActions() ;
    }

    protected  void createActions() {
        String[] actionAttrbs={
           ACTION_UP,"Move an item up",
           ACTION_DOWN,"Move an item down",
           ACTION_TOP,"Move an item to top",
           ACTION_BOTTOM,"Move an item to bottom",
           ACTION_RIGHT,"Select an item",
           ACTION_LEFT,"Deselect an item",
           ACTION_RIGHTALL,"Select all items",
           ACTION_LEFTALL,"Deselect all items"
        } ;
        for (int i=0;i<actionAttrbs.length ;i=i+2){
            String actName=actionAttrbs[i];
            String tooltip=actionAttrbs[i+1];
            Action action=this.createAction(actName,tooltip);
            this.actmaps.put(actName,action);
        }

    }

    public boolean processAction(String btnName) {
        //this.app.act
        //"Right","Left","Right all","Left all","Up","Down","Apply"
        if(btnName.equals(ACTION_RIGHT) ){
            this.app.moveRight();
        }
        else if(btnName.equals(ACTION_LEFT) ){
            this.app.moveLeft() ;
        }
        else if(btnName.equals(ACTION_UP)){
            this.app.moveUp();

        }
        else if(btnName.equals(ACTION_DOWN)){
            this.app.moveDown() ;
        }
        else if (btnName.equals(ACTION_RIGHTALL)){
            this.app.moveAllRight() ;
        }
        else if (btnName.equals(ACTION_LEFTALL)){
             this.app.moveAllLeft() ;
        }
        else if (btnName.equals(ACTION_TOP)){
             this.app.moveTop() ;
             //System.out.println("Top");
        }
         else if (btnName.equals(ACTION_BOTTOM)){
             this.app.moveBottom() ;
             //System.out.println("Bottom");
        }
         else if (btnName.equals(ACTION_APPLY)){
             this.app.apply() ;
             //System.out.println("Apply");
        }
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }


    protected ImageIcon getImageIcon(String name) {
        ImageIcon imageIcon = ImageUtils.getImageIcon(ActionManager.class,name);
        //System.out.println("loaded image:"+imageIcon);
        return imageIcon;
    }

    public void setupToolbar(ActionMap actionMap) {
        //To change body of implemented methods use File | Settings | File Templates.
    }

    public void setApp(SelectItemsPane app) {
        this.app = app;
    }
}
